Skip to content

test: add IPNS/DNSLink with sub-path in value field#273

Merged
lidel merged 2 commits intomainfrom
test/ipns-record-subpath
Feb 24, 2026
Merged

test: add IPNS/DNSLink with sub-path in value field#273
lidel merged 2 commits intomainfrom
test/ipns-record-subpath

Conversation

@lidel
Copy link
Member

@lidel lidel commented Feb 24, 2026

existing IPNS/DNSLink tests only cover records whose Value is a bare /ipfs/<cid>.

this PR adds basic tests to verify gateways correctly handle IPNS/TXT records where value contains a sub-path (e.g. /ipfs/<cid>/root2).

Changes:

  • TestGatewayIPNSRecordWithSubpath verifies gateways handle IPNS records where Value contains a sub-path (e.g. /ipfs/<cid>/root2). Later simplified to only test file retrieval (directory listing case removed).
  • TestDNSLinkGatewayWithSubpath verifies gateways handle DNSLink TXT records with sub-paths (e.g. dnslink=/ipfs/<cid>/root2).
  • Reuses gateway-cache/fixtures.car and extends the shared IPNS record generator with makeSubpathRecord().

existing IPNS tests only cover records whose Value is a bare /ipfs/<cid>.
add TestGatewayIPNSRecordWithSubpath to verify gateways correctly handle
IPNS records where Value contains a sub-path (e.g. /ipfs/<cid>/root2),
testing both directory listing and file retrieval through path
concatenation.

reuses gateway-cache/fixtures.car and extends the shared IPNS record
generator with makeSubpathRecord().
@lidel lidel changed the title test: add IPNS record with sub-path in Value field test: add IPNS/DNSLink with sub-path in value field Feb 24, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Results against Kubo master:

Summary

Tests Failures Errors Skipped
1258 0 0 0

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Results against Kubo latest:

Summary

Tests Failures Errors Skipped
1258 26 0 0

add TestDNSLinkGatewayWithSubpath to verify gateways handle DNSLink TXT
records where the path includes a sub-path (e.g. dnslink=/ipfs/<cid>/root2).

also simplify TestGatewayIPNSRecordWithSubpath to only test file
retrieval, removing the directory listing case.
@github-actions
Copy link
Contributor

v0.11.1

Added

  • New test TestGatewayIPNSRecordWithSubpath for IPNS records whose Value field contains a sub-path (e.g. /ipfs/<cid>/root2). All prior IPNS tests only covered bare /ipfs/<cid> in the record Value.
  • New test TestDNSLinkGatewayWithSubpath for DNSLink TXT records pointing at a content path with a sub-path (e.g. dnslink=/ipfs/<cid>/root2).

RunWithSpecs(t, tests, specs.PathGatewayIPNS)
}

func TestGatewayIPNSRecordWithSubpath(t *testing.T) {
Copy link
Member Author

@lidel lidel Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explainer for posterity/llms (this is about IPNS, but similar applies to DNSLink one)


TestGatewayIPNSRecordWithSubpath

Verifies that a gateway correctly resolves IPNS records whose Value field
contains a sub-path (e.g. /ipfs/<cid>/sub/path) rather than a bare CID.

Shared fixture: gateway-cache/fixtures.car

A CARv1 file containing a UnixFS directory tree:

bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui   (ROOT1_CID) ./
└── root2/
    └── root3/
        └── root4/
            └── index.html  ->  "hello\n"

Key CIDs:

Alias CID Path
ROOT1_CID bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui ./
ROOT2_CID bafybeih2w7hjocxjg6g2ku25hvmd53zj7og4txpby3vsusfefw5rrg5sii ./root2
ROOT3_CID bafybeiawdvhmjcz65x5egzx4iukxc72hg4woks6v6fvgyupiyt3oczk5ja ./root2/root3
ROOT4_CID bafybeifq2rzpqnqrsdupncmkmhs3ckxxjhuvdcbvydkgvch3ms24k5lo7q ./root2/root3/root4
FILE_CID bafkreicysg23kiwv34eg2d7qweipxwosdo2py4ldv42nbauguluen5v6am ./root2/root3/root4/index.html

IPNS record

Generated by makeSubpathRecord() in fixtures/ipns_records/generator/main.go.
It creates a valid V1+V2 IPNS record with a random Ed25519 key pair. The record's
Value field points at ROOT1_CID with a sub-path appended:

Value = /ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2

The resulting IPNS key (base36):

SUBPATH_IPNS_ID = k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c

The signed record is committed as a binary fixture at
fixtures/gateway-cache/k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c.ipns-record.

Test request

GET /ipns/k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c/root3/root4/index.html

Resolution steps

  1. Gateway parses the request path:

    • namespace: /ipns/
    • IPNS key: k51qzi5uqu5djokp3m1keo36hoxtd6u3a1d2rg1camf6al7p3huy63dojlm57c
    • remaining path: /root3/root4/index.html
  2. Gateway fetches and validates the IPNS record for that key.

  3. Extracts the Value from the record:
    /ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2

  4. Concatenates the remaining request path onto the resolved Value:

    /ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2 + /root3/root4/index.html
    

    Final content path:

    /ipfs/bafybeib3ffl2teiqdncv3mkz4r23b5ctrwkzrrhctdbne6iboayxuxk5ui/root2/root3/root4/index.html
    
  5. Resolves through the UnixFS DAG in fixtures.car:
    ROOT1_CID -> root2/ -> root3/ -> root4/ -> index.html

  6. Expected response: 200 with body hello\n

Why this matters

All prior IPNS tests used records whose Value was a bare /ipfs/<cid> with no
trailing path segments. This test covers the case where the IPNS record itself
embeds a sub-path in its Value. Gateways must concatenate the request path
after the full resolved Value, not just after the CID.

@lidel lidel marked this pull request as ready for review February 24, 2026 17:00
@lidel lidel merged commit 8b70156 into main Feb 24, 2026
10 checks passed
@lidel lidel deleted the test/ipns-record-subpath branch February 24, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant